<?php
/**
 * Created by PhpStorm.
 * User: VJLau
 * Date: 2018/2/5
 * Time: 下午12:29
 */
$uniacid = $_W['uniacid'];
//获取区域
$regions = pdo_fetchall("SELECT * FROM " . tablename('bontrip_region') .
    " WHERE uniacid= '{$uniacid}' AND deleted_at is null ORDER BY sort ASC,id DESC");

//获取绑定第一个区域的目的地
if (!empty($regions)) {
    $dests = pdo_fetchall("SELECT * FROM " . tablename('bontrip_dest') .
        " WHERE region_id = " . $regions[0]['id'] . " AND uniacid= '{$uniacid}' AND deleted_at is null ORDER BY sort ASC,id DESC");
}else{
    $dests = null;
}

//处理目的地数据，每三个为一组
$num = ceil(count($dests)/3);
$dests_list = array();
for($i = 0; $i < $num;$i++){
    for ($j = 0;$j < 3;$j++){
        if(!empty($dests[$j+$i*3])){
            $dests_list[$i][] = $dests[$j+$i*3];
        }else{
            $dests_list[$i][] = null;
        }
    }
}


$title = "目的地";
include $this->template('destination');